﻿#include "FITKGraphObjectModelBase.h"

// Graph 
#include "FITKGraphCommons.h"
#include "FITKGraphObjectModelHighlighting.h"
#include "FITK_Interface/FITKVTKAlgorithm/FITKGraphActor.h"

namespace Exchange
{
    FITKGraphObjectModelBase::FITKGraphObjectModelBase(AbaqusData::FITKDataCase* caseData, Core::FITKAbstractDataObject* dataObj)
        : FITKGraphObject3D(caseData, dataObj)
    {
        // Set the layer need to be rendered.
        // Each model graph object has an additional graph object
        // for highlighting, so the highlight layer is 0.
        setRenderLayer(0, 0);

        // Save if the bounds are fixed or dynamic.
        m_hasFixedBounds = true;
    }

    void FITKGraphObjectModelBase::init()
    {
        // Create a new graph object for highlighting and pre-highlighting the model.
        m_graphObjHighlight = new FITKGraphObjectModelHighlighting(m_caseData, _dataObj);
        m_graphObjHighlight->setRepresentation(1);
        m_graphObjHighlight->setColor(FITKGraphCommons::s_highlightColor);
        m_addinGraphObjList.push_back(m_graphObjHighlight);

        m_graphObjPreHighlight = new FITKGraphObjectModelHighlighting(m_caseData, _dataObj);
        m_graphObjPreHighlight->setRepresentation(1);
        m_graphObjPreHighlight->setColor(FITKGraphCommons::s_preHighlightColor);
        m_addinGraphObjList.push_back(m_graphObjPreHighlight);
    }

    void FITKGraphObjectModelBase::setTransparent(bool isOn)
    {
        Q_UNUSED(isOn);
    }

    void FITKGraphObjectModelBase::setFeatureVisible(bool visibility)
    {
        Q_UNUSED(visibility);
    }

    void FITKGraphObjectModelBase::highlight(QColor color)
    {
        // If the object is invisible, then return.
        if (!m_graphObjHighlight || !getDataVisibility())
        {
            return;
        }

        m_graphObjHighlight->highlight(color);

        this->Superclass::highlight(color);
    }

    void FITKGraphObjectModelBase::disHighlight()
    {
        if (m_graphObjHighlight && m_isHighlighting)
        {
            m_graphObjHighlight->disHighlight();
        }

        if (m_graphObjPreHighlight && m_isPreHighlighting)
        {
            m_graphObjPreHighlight->disHighlight();
        }

        this->Superclass::disHighlight();
    }

    void FITKGraphObjectModelBase::preHighlight()
    {
        // If the object is invisible, then return.
        if (!m_graphObjPreHighlight || !getDataVisibility())
        {
            return;
        }

        m_graphObjPreHighlight->highlight(FITKGraphCommons::s_preHighlightColor);

        this->Superclass::preHighlight();
    }

    void FITKGraphObjectModelBase::setPointVisible(bool visible)
    {
        Q_UNUSED(visible);
    }

    void FITKGraphObjectModelBase::setPointProperties(int pixelSize, QColor color)
    {
        Q_UNUSED(pixelSize);
        Q_UNUSED(color);
    }

    void FITKGraphObjectModelBase::setColorMode(ColorMode mode)
    {
        // Set the color mode by the value.
        switch (mode)
        {
        case ColorMode::ColorDefault:
        {
            colorByDefault();
            break;
        }
        case ColorMode::ColorDefaultProperty:
        {
            colorByDefaultProperty();
            break;
        }
        case ColorMode::ColorSection:
        {
            colorBySection();
            break;
        }
        case ColorMode::ColorMaterial:
        {
            colorByMaterial();
            break;
        }
        case ColorMode::ColorDoubleFaces:
        {
            colorByDoubleFaces();
            break;
        }
        case ColorMode::ColorDefaultMesh:
        {
            colorByDefaultMesh();
            break;
        }
        default:
            break;
        }
    }

    ColorMode FITKGraphObjectModelBase::getCurrentColorMode()
    {
        return m_colorMode;
    }
}   // namespace Exchange